/**
 * 
 */
package com.googlecode.dynargs.util;

import java.io.PrintStream;

/**
 * @author Federico De Faveri defaveri@gmail.com
 *
 */
public class IndentedWriter  {
	
	protected PrintStream writer;
	protected String indentationString;
	protected int indentation;
	
	public IndentedWriter()
	{
		this(System.out, " ");
	}
	
	public IndentedWriter(PrintStream writer, String indentationString)
	{
		this.writer = writer;
		this.indentationString = indentationString;
		this.indentation = 0;
	}
	
	/**
	 * @return the indentation
	 */
	public int getIndentation() {
		return indentation;
	}

	/**
	 * @param indentation the indentantion to set
	 */
	public void setIndentation(int indentation) {
		this.indentation = indentation;
	}

	public void inc()
	{
		indentation++;
	}
	
	public void dec()
	{
		indentation--;
		indentation = Math.max(0, indentation);
	}
	
	protected void addIntendation()
	{
		for (int i = 0; i < indentation; i++) writer.append(indentationString);
	}
	
	public void println(String line)
	{
		addIntendation();
		writer.println(line);
	}


}
